package com.lanju.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Test {

	public static void main(String[] args) {
		calPreday("20180610");
	}
	public static String calPreday(String date){
		Date date_ = null;
		String year=date.substring(0, 4);
		String month=date.substring(4, 6);
		String day=date.substring(6, date.length());
		System.out.println(year+"-"+month+"-"+day);
		Calendar c=Calendar.getInstance();
		try {
			date_=new SimpleDateFormat("yyy-MM-dd").parse(year+"-"+month+"-"+day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date_);
		int day_=c.get(Calendar.DATE);
		c.set(Calendar.DATE, day_-1);
		System.out.println("当前时间是"+c.getTime());
		String dayBefore=new SimpleDateFormat("yyyyMMdd").format(c.getTime());
		return dayBefore;
	}
}
